package com.globo.devsup.client.presenter;

import com.globo.devsup.client.presenter.listener.LoginListener.LoginWindowListener;
import com.globo.devsup.client.presenter.listener.LoginListener.SubmitButtonListener;
import com.globo.devsup.client.rpc.LoginRPC;
import com.globo.devsup.client.rpc.LoginRPCAsync;
import com.globo.devsup.client.view.IView;
import com.globo.devsup.client.view.LoginView;
import com.globo.devsup.client.vo.BaseVO;
import com.google.gwt.core.client.GWT;

public class LoginPresenter extends BasePresenter {
	
	public LoginPresenter() {
		setView(new LoginView(this));
    }
    
    public IView pack() {
        return (LoginView)super.pack();
    }
    
    public void setUpViewListeners() {
        LoginView view = ((LoginView)getView());
        view.setWindowActionListener(new LoginWindowListener(this));
        view.setSubmitActionListener(new SubmitButtonListener(this));
    }
    
    public void updateModelFromView(BaseVO vo) {
        
    }
    
    public void updateViewFromModel(BaseVO vo) {
        
    }

    
    /**
     * ######################## STRATEGIES ########################
     */
    
    public final Strategy LOAD_WINDOW_STRATEGY = new LoadWindowStrategy();
    public final Strategy SUBMIT_STRATEGY = new SubmitStrategy();
    
    private class LoadWindowStrategy implements Strategy {
        public void execute() {
        	((LoginView)getView()).getEl().setStyle("z-index","20010");
        }
    }
    
    private class SubmitStrategy implements Strategy {
        public void execute() {
        	LoginRPCAsync loginrpc = (LoginRPCAsync)GWT.create(LoginRPC.class);
			loginrpc.validate(login.userName.getValueAsString(), login.pass.getValueAsString(), login.globoNet.getValueAsString(), callback);
			principalPanel.getEl().unmask();
			login.close();
        }
    }
}
